﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Security.Cryptography;

namespace EncrypterMD5
{ /// <summary> 
    /// Summary description for MD5. 
    /// </summary> 
    public class MD5
    {
        public static string Md5(string str, int code)
        {
            //str = System.Web.HttpUtility.UrlEncode(str); 
            if (code == 16) //16位MD5加密（取32位加密的9~25字符） 
            {
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
                
            }
            else//32位加密 
            {
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
            }

        }
    }
}
